<script type="text/javascript">
this.imagePreview = function(){ 
    /* CONFIG */
        
        xOffset = 10;
        yOffset = 30;
        
        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result
        
    /* END CONFIG */
    $("a.preview").hover(function(e){
        this.t = this.title;
        this.title = "";    
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $(this).append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");

        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .fadeIn("fast");                        
    },
    function(){
        this.title = this.t;    
        $("#preview").remove();
    }); 
    $("a.preview").mousemove(function(e){
        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px");
    });         
};


// starting the script on page load
$(document).ready(function(){
    imagePreview();
});
</script>
<style>
body {
    margin:0;
    padding:40px;
    background:#fff;
    font:80% Arial, Helvetica, sans-serif;
    color:#555;
    line-height:180%;
}

h1{
    font-size:180%;
    font-weight:normal;
    color:#555;
}
h2{
    clear:both;
    font-size:160%;
    font-weight:normal;
    color:#555;
    margin:0;
    padding:.5em 0;
}
a{
    text-decoration:none;
    color:#f30; 
}
p{
    clear:both;
    margin:0;
    padding:.5em 0;
}
pre{
    display:block;
    font:100% "Courier New", Courier, monospace;
    padding:10px;
    border:1px solid #bae2f0;
    background:#e3f4f9; 
    margin:.5em 0;
    overflow:auto;
    width:800px;
}
img{border:none;}
ul,li{
    margin:0;
    padding:0;
}
li{
    list-style:none;
    float:left;
    display:inline;
    margin-right:10px;
}
#preview{
    position:absolute;
    border:1px solid #ccc;
    background:#333;
    padding:5px;
    display:none;
    color:#fff;
    }
</style>

<body>

    <h1>Easy Image Preview with jQuery</h1>

    <h2>Image gallery (with caption)</h2>

    <ul>
        <% HotelRoomType.where('hotel_id =?', 56).each do |hrt| %>
            <% hrt.hotel_room_type_images.each do |hrti| %>
                <li>
                    <a href="<%= hrt.primary_picture.url(:large) %>" class="preview" title="Lake and a mountain"><%= image_tag hrt.primary_picture.url(:small), alt: "gallery thumbnail" %></a>
                </li> 
            <% end %>
        <% end %>
    </ul>
    

</body>
</html>
